<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Repos\UserRepo;
use App\Repos\UserCouponRepo;

class UserController extends Controller
{
    public function index(Request $request)
    {
    	$param = [];
        if($request->keyword) {
            $param['keyword'] = trim($request->keyword);
        }
        $list = UserRepo::getList($param);
        //var_dump($param);die;
    	return view('admin.user.index',compact('list','param')); 
    }

    public function show($user_id)
    {
        $data = UserRepo::find(['id'=>$user_id]);
        return view('admin.user.show',compact('data'));
    }

    public function update(Request $request,$id)
    {
        
        $rs['status'] = 'danger';
        $rs['msg']    = 'Failed';
        $data = $request->except(['_token','_method']);
     
        $flag = UserRepo::update(['id'=>$id],$data);
        if($flag) {
            $rs['status'] = 'success';
            $rs['msg'] = 'Sucess!';
        }
        return redirect('zadmin/users')->with('rs',$rs);
    }

  

    

    public function edit($user_id)
    {
        $data = UserRepo::find(['id'=>$user_id]);
      
        return view('admin.user.edit',compact('data'));
    }

     public function destroy($id)
    {
        $flag = UserRepo::destroy($id);
        return back();
    }

    
}
